﻿function startProcess(holder) {
    holder.text("");
    holder.addClass("processing-small");
}
function endProcess(holder, message, state) {
    holder.removeClass("processing-small");
    if (state == "Succeed") {
        holder.removeClass("error");
        holder.addClass("message");
    }
    else {
        holder.removeClass("message");
        holder.addClass("error");
    }
    holder.text(message);
}
//为所有.username a标签添加click函数
$(function () {
    var username;
    var realname;
    var jdiv = $(document.createElement("div"));
    jdiv.append("<div id='info_processing'><span class='error'>加载中...</span></div>");
    jdiv.append("<div><span id='info_message' class='error'></span></div>");
    jdiv.append("<div id='info_content'></div>");
    var content = $("#info_content", jdiv);
    content.append("<table></table>");
    var table = $("table", content);
    table.append("<tr><td>真实姓名</td><td id='_Name'></td></tr>");
    table.append("<tr><td>性别</td><td id='_Gender'></td></tr>");
    table.append("<tr><td>生日</td><td id='_BirthDay'></td></tr>");
    table.append("<tr><td>技术头衔</td><td id='_TechnicalTitle'></td></tr>");
    table.append("<tr><td>最高学历</td><td id='_HighestDegree'></td></tr>");
    table.append("<tr><td>所学专业</td><td id='_Major'></td></tr>");
    table.append("<tr><td>从事专业</td><td id='_Occupation'></td></tr>");
    jdiv.dialog({
        closeOnEscape: true,
        minWidth: 455,
        title: "用户/人员信息",
        autoOpen: false,
        modal: true,
        buttons: [{
            text: "关闭",
            click: function () { jdiv.dialog("close"); }
        }],
        open: function (event, ui) {
            var url, param;
            var d = new Date();
            if (username != null) {
                url = "/User/ajaxPersonInfoByUserName";
                param = { "username": username, "_": d.getMilliseconds() };
            }
            else {
                url = "/Person/ajaxPersonInfoByRealName";
                param = { "realname": realname, "_": d.getMilliseconds() };
            }
            $.get(
                url,
                param,
                function (data) {
                    if (data.State == "Succeed") {
                        var _data = username == null ? data.Data[0] : data.Data;
                        $("#_Name").text(_data.Name);
                        if (_data.Gender == "Female") $("#_Gender").text('女');
                        else $("#_Gender").text('男');
                        $("#_BirthDay").text(_data.BirthDay);
                        $("#_TechnicalTitle").text(_data.TechnicalTitle);
                        $("#_HighestDegree").text(_data.HighestDegree);
                        $("#_Major").text(_data.Major);
                        $("#_Occupation").text(_data.Occupation);
                        $("#info_message").text("");
                        $("div#info_processing").hide();
                        $("div#info_content").show();
                    } else {
                        $("div#info_processing").hide();
                        $("div#info_content").hide();
                        $("span#info_message ").text(data.Message);
                    }
                }
            );
        },
        close: function (event, ui) {
            $("div#info_processing").show();
            $("div#info_content").hide();
            $("span#info_message ").text("");
        }
    });
    $(".username").live('click', function () {
        username = $(this).text();
        realname = null;
        jdiv.dialog("open");
    });
    $(".realname").live('click', function () {
        realname = $(this).text();
        username = null;
        jdiv.dialog("open");
    });

});
